#ifndef PARTICLESYSTEMCS_H
#define PARTICLESYSTEMCS_H

#include "particleSystem.h"


class ParticleSystemCS : public ParticleSystem
{
    public:

        // this is maybe not the best way, but we need some other info for the physics
        struct ParticleCS
        {
            Vector3f    oldPos;     // save preious position for updating physics
            float       drag;       // drag to give them nice motion
            float       blink;      // not implemented ? - for each to have varying blink rate

        };

        // Let's make the attractors particles so we kow their birthday.
        // Each particle in this system can be attracted to a different position so 1 per particle
        std::vector<Particle>   attractors;
        std::vector<ParticleCS> particlesX;

        float timeStep, timeStep2;          // time step for physics
        float diameter;                     // size of particle system world
        float force;                        // force towards attractor

        // center point of the swarm
        // all attractors are a given distance from this point and it can change so they have
        // a nice flight pattern
        Particle swarmCentre;

        Actor* myTarget;                    //particleSystem we morph to

        ParticleSystemCS();
        virtual ~ParticleSystemCS();

        virtual void registerProperties();
        virtual void setup();
        virtual void create();
        virtual void trigger( Actor * other );

        // creates random particles + attractors and setsup the physics parameters
        // calls addRandomAttractors() + setupPhysics()
        virtual void addRandomParticles(int amount, float diameter);

        // updates the physics simulation
        virtual void update(double deltaTime);

        // sets the attractor positions to points in particles
        // if points is greater than the number of particles, new ones are created
        // waitTime indicates how long until they return to random movement
        virtual void setAttractorsFromParticles( vector<Particle> points, int waitTime);

        // draw
        virtual void drawParticles();

        // draws atractor positions for debugging
        virtual void drawAttractors();

    protected:

        // adds a random attractor for each particle
        virtual void addRandomAttractors(float diameter);

        // sets up additional physics for each particle
        virtual void setupPhysics();

        // solve physcis simulation updating the position based on last position and current
        virtual void doVerlet();

        // updates position based on attraction
        virtual void solveAttractions(double deltaTime);

        // custom simulation
        // periodically alters the center of the swarms and the attractors of the particles
        // particles birth is used to countdown until next change
        virtual void simRandomAttraction(double deltaTime);


    private:
};

#endif // PARTICLESYSTEMCS_H
